/*
 * @Author: Jie
 * @LastEditors: Jie
 * @Date: 2021-05-10 08:51:34
 * @LastEditTime: 2021-06-02 09:10:32
 * @Description:
 * @Email: 18521721605@163.com
 */
import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);



export default new Vuex.Store({
  state: {
    title: "我是全局title",
    todos: [
      { id: 1, text: "...", done: true },
      { id: 2, text: "...", done: false },
    ],
  },
  mutations: {
    edit(state, canshu) {
      state.title = "修改state数据";
      console.log(canshu);
    },
  },
  getters: {
    doneTodos: (state) => {
      //过滤
      return state.todos.filter((item) => item.done);
    },
  },
  actions: {
    aEdit(context, canshu) {
      setTimeout(() => {
        context.commit("edit", canshu);
      }, 2000);  // 延迟几秒执行

      //setInterval() //规定间隔多长时间执行一次
    },
  },
  modules: {
  },
});
